
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import router from './router'
import { initDynamicRoutes, addDynamicRoutes } from './router'
declare module 'vue-router' {
    interface RouteMeta {
        detail: string
    }
}

const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
function checkRouter(path: string) {
    let hasRouter = router.getRoutes().filter(route => route.path == path).length
    if (hasRouter) {
        return true
    } else {

        return false;
    }
}
router.beforeEach(async(to, from, next) => {
    document.title = to.meta.detail as string
    if (!localStorage.getItem('token') && to.name
        !== 'login') {
        next({ name: 'login' })
    }
    else {
        next()
    }
})
const init = async () => {
    await initDynamicRoutes() // 等待路由加载完成
    app.use(router)
    app.mount('#app')
  }
app.use(createPinia())

init()